//
//  SYDAccount.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/9/26.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDAccount.h"

@implementation SYDAccount

/**
 *  当一个对象要归档到沙盒中的时候 就会调用这个方法
 目的：在这个方法中说明这个对象的哪些属性要存进沙盒
 
 */
- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.accountStatus forKey:@"accountStatus"];
    [aCoder encodeObject:self.birthday forKey:@"birthday"];
    [aCoder encodeObject:self.cityCode forKey:@"cityCode"];
    [aCoder encodeObject:self.cityName forKey:@"cityName"];
    [aCoder encodeObject:self.headImageUrl forKey:@"headImageUrl"];
    [aCoder encodeObject:self.mobilephone forKey:@"mobilephone"];

    [aCoder encodeObject:self.userId forKey:@"userId"];
    [aCoder encodeObject:self.username forKey:@"username"];
    [aCoder encodeObject:self.busSeats forKey:@"busSeats"];
    [aCoder encodeObject:self.vehicleId forKey:@"vehicleId"];
    [aCoder encodeObject:self.token forKey:@"token"];
    [aCoder encodeObject:self.invaildDate forKey:@"invaildDate"];
    
//    unsigned int count = 0;
//    objc_property_t * propertes = class_copyPropertyList([self class], &count);
//    for (NSInteger i = 0; i < count; i++) {
//        const char * propertyName = property_getName(propertes[i]);
//        NSString * name = [NSString stringWithUTF8String:propertyName];
//        id value = [self valueForKey:name];
//        [aCoder encodeObject:value forKey:name];
//    }
}

/**
 *  当从沙盒中解档一个对象（从沙盒中加载一个对象）就要调用该方法
 目的：在这个方法中说明沙盒中的属性该怎么解析（需要取出哪些属性）
 */

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        self.accountStatus = [aDecoder decodeObjectForKey:@"accountStatus"];
        self.birthday = [aDecoder decodeObjectForKey:@"birthday"];
        self.cityCode = [aDecoder decodeObjectForKey:@"cityCode"];
        self.cityName = [aDecoder decodeObjectForKey:@"cityName"];
        self.headImageUrl = [aDecoder decodeObjectForKey:@"headImageUrl"];
        self.mobilephone = [aDecoder decodeObjectForKey:@"mobilephone"];

        self.userId = [aDecoder decodeObjectForKey:@"userId"];
        self.username = [aDecoder decodeObjectForKey:@"username"];
        self.busSeats = [aDecoder decodeObjectForKey:@"busSeats"];
        self.vehicleId = [aDecoder decodeObjectForKey:@"vehicleId"];
        self.token = [aDecoder decodeObjectForKey:@"token"];
        self.invaildDate = [aDecoder decodeObjectForKey:@"invaildDate"];
        
//        unsigned int count = 0;
//        objc_property_t * propertes = class_copyPropertyList([self class], &count);
//        for (NSInteger i = 0; i < count; i++) {
//            const char * propertyName = property_getName(propertes[i]);
//            NSString * name = [NSString stringWithUTF8String:propertyName];
//            id value = [self valueForKey:name];
//            [aDecoder setValue:value forKey:name];
//        }
    }
    return self;
}
@end
